package org.example;

/**
 * @ClassName 包装类型数值比较
 * @Description
 * @Author zhangsw
 * @Date 2020/10/20 9:54
 * @Version 1.0
 */
public class 包装类型数值比较 {
    public static void main(String[] args) {
        Integer i = 128;
        Integer j = 128;
        System.err.println("i == j=" + (i == j));
        System.out.println("i.equals(j)=" + (i.equals(j)));
        System.err.println("i.intValue() == j.intValue()=" + (i.intValue() == j.intValue()));//true
        Integer m = 127;
        Integer n = 127;
        System.err.println("m == n=" + (m == n));
        System.out.println("m.equals(n)=" + (m.equals(n)));
        System.err.println("m.intValue() == n.intValue()=" + (m.intValue() == n.intValue()));//true

        int int1 = 12;
        int int2 = 12;

        Integer integer1 = new Integer(12);
        Integer integer2 = new Integer(12);
        Integer integer3 = new Integer(127);

        Integer a1 = 127; //或者写成Integer a1 = Integer.valueOf(127);
        Integer a2 = 127;//或者写成Integer a2 = Integer.valueOf(127);

        Integer a = 128;
        Integer b = 128;

        System.out.println("int1 == int2 -> " + (int1 == int2));
        System.out.println("int1 == integer1 -> " + (int1 == integer1));
        System.out.println("integer1 == integer2 -> " + (integer1 == integer2));
        System.out.println("integer3 == a1 -> " + (integer3 == a1));
        System.out.println("a1 == a2 -> " + (a1 == a2));
        System.out.println("a == b -> " + (a == b));

        /**
         * 答案：
         *  1、   int1 == int2 -> true
         * 2、   int1 == integer1 -> true
         * 3、   integer1 == integer2 -> false
         * 4、   integer3 == a1 -> false
         * 5、   a1 == a2 -> true
         * 6、   a == b -> false
         */
    }
}
